home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / fido / shelter191a.lha / rexx / wfreqit-check.rexx < prev    next >
OS/2 REXX Batch file  |  1994-05-04  |  9KB  |  269 lines

  1. /**/ 
  2. v="$VER: WFREQIT-CHECK Rexx  Check Incoming for Users  Williamson/Mollitt  54.00"
  3. /*
  4.     Based on FREQIT-IN.rx by Sean Mollitt
  5.  
  6.     This script should be run aftersession if requests have been sent out.
  7.     If called during a cron event, it will scan the defined freq dir.
  8.  
  9.     What it does is check any file recd matches those requested by a user
  10.     (FREQIT.usr). If a match is found the file is moved to a special 
  11.     area and a message left for the user which he will receive next time
  12.     he uses FREQIT.
  13.     The  log  file  is updated, the file name is removed from the user file
  14.     and the user file is saved.  
  15. */ 
  16.  
  17. sv='v'||right(v,4)
  18. script="WfreqIt"
  19. call close('STDOUT')
  20. call open('STDOUT','RAW:0/10/640/130/ROOF 'script sv'/INACTIVE/AUTO/SCREEN'||GetClip('ASYNCSCREEN'),'w')
  21. call close('STDIN')
  22. call open('STDIN','*','R')
  23.    
  24.  
  25. /*-------------------------------------- User variables */
  26.  configpath = "CFG:freqit/freqit.cfg"
  27. /*----------------------------------------------------- */
  28.  
  29.     x=0;z=0;c=0;e=0;up=0;m=0;totk=0;totusers=0
  30.  
  31.     SAY "WfreqIt-Check "sv" Copyright 1993 Sean Mollitt & Robert Williamson"  
  32.  
  33.     IF ~show('L','rexxsupport.library') then
  34.         IF ~addlib('rexxsupport.library',0,-30,0) then do
  35.             say 'Error loading rexxsupport.library.'  
  36.             exit
  37.         end
  38.  
  39.  
  40. openconfigfile:
  41.  
  42.     IF ~OPEN('config',configpath,'R') then do
  43.         SAY "Error! Cannot find the config file (freqit.cfg) "    
  44.         signal shutdown
  45.     END
  46.  
  47. readconfigline:
  48.     cfgln = TRANSLATE(READLN('config'),' ','09'x) /* strips tabs out of config */
  49.     IF LEFT(STRIP(cfgln),1) ~= ';' & COMPRESS(cfgln) ~= "" then DO
  50.         x=x+1
  51.         IF STRIP(WORD(cfgln,1))='BBSLIST' then DO
  52.             z=z+1
  53.             bbsname.z  = STRIP(TRANSLATE(READLN('config'),' ','09'x))
  54.             offset= POS(';',bbsname.z)-1
  55.             IF offset > 0 then bbsname.z = STRIP(LEFT(bbsname.z,offset)) 
  56.             filelist.z = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  57.             node.z     = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  58.             time.z     = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  59.             type.z     = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  60.             access.z   = WORD(STRIP(TRANSLATE(READLN('config'),' ','09'x)),1)
  61.             signal readconfigline
  62.         END 
  63.         cfg.x = STRIP(STRIP(WORD(cfgln,2)),'B','"')
  64.     END
  65.  
  66. IF ~EOF('config') then signal readconfigline
  67.  
  68. filedir = cfg.1
  69. indir   = cfg.2
  70. maxreq  = cfg.3
  71. maxk    = cfg.4
  72. maxover = cfg.5
  73. callout = cfg.6
  74. outnode = cfg.7
  75. txtfile = cfg.8
  76. hlpfile = cfg.9
  77. usrfile = cfg.10
  78. logfile = cfg.11
  79. msgtxt  = cfg.12
  80. msgarea = cfg.13
  81. netarea = cgf.14
  82. maxdays = cfg.15
  83. outbound = cfg.16
  84. pollcmd = cfg.17
  85. hostaddr = cfg.18
  86. userfs=cfg.19
  87. loggroup=cfg.20
  88.  
  89.     parse arg scandir .
  90.     if arg()=0 then scandir=indir
  91.         else scandir=addslash(scandir)
  92.  
  93. openuserfile:
  94.     IF ~OPEN('user',usrfile,'R') then do
  95.         SAY "Error! Cannot find the user file (freqit.usr) "  
  96.         signal shutdown
  97.     END
  98.  
  99.     say "Loading user config"
  100. readuserfile:    
  101.     usrline = UPPER(READLN('user'))
  102.     IF EOF('user') then signal freqit
  103.     m=m+1 ; i=0 ; files.m=0
  104.     name.m= usrline
  105.     totusers = m
  106.     DO FOREVER
  107.         i=i+1
  108.         usrline = READLN('user')
  109.         IF WORD(usrline,1)= "#" then BREAK
  110.         PARSE VAR usrline file.m.i filek.m.i filed.m.i filea.m.i filestat.m.i fileto.m.i filedes.m.i
  111.         files.m = i
  112.     END
  113.  
  114.     IF ~EOF('user') then signal readuserfile
  115.  
  116. freqit:
  117.  
  118.     CALL CLOSE('user')
  119.     if m=0 then DO
  120.         call putlog("FREQIT.usr is empty. No files waiting")
  121.         signal shutdown
  122.     END
  123.  
  124.     call putlog('Scanning 'scandir)
  125.     inlist = UPPER(SHOWDIR(scandir,'F'))
  126.     if inlist="" then do
  127.         say scandir' is empty'
  128.         signal shutdown
  129.     end
  130.  
  131.     i=0
  132.     DO FOREVER
  133.         i=i+1
  134.         PARSE VAR inlist infile.i inlist
  135.         IF infile.i == "" then BREAK
  136.     END
  137.     i=i-1
  138.  
  139.     DO x = 1 to i
  140.         DO a = 1 to totusers
  141.             DO b = 1 to files.a
  142.                 IF UPPER(file.a.b) = UPPER(infile.x) & filestat.a.b = 'waiting' then DO
  143.                     c=c+1
  144.                     usermsg=msgarea||TRANSLATE(name.a,'_',' ')
  145.  
  146.                     if ~exists(usermsg) then address COMMAND "Copy" msgtxt usermsg
  147.                         
  148.                     call putlog(file.a.b||" received for "||name.a||". "||TRANSLATE(fileto.a.b,' ','_')||" notified.") 
  149.                     say file.a.b||" received for "||name.a||". "||TRANSLATE(fileto.a.b,' ','_')||" notified." 
  150.  
  151.  
  152.                     openmode='a'
  153.                     IF ~OPEN('msgadd',usermsg,'A') then do
  154.                         If ~open('msgadd',usermsg,'W') then do
  155.                             SAY "Error opening "usermsg   
  156.                             signal shutdown
  157.                         end
  158.                         openmode='w'
  159.                     END
  160.  
  161.                     filedes.a.b = STRIP(COMPRESS(filedes.a.b,'"'),'B')
  162.             
  163.                     if indir ~= scandir then do
  164.                         address COMMAND 'Copy' scandir||file.a.b indir
  165.                         if RC=0 then do
  166.                             call delete(scandir||file.a.b)
  167.                             say scandir||file.a.b 'moved to 'indir
  168.                         end
  169.                     end
  170.                     address COMMAND 'FileNote' indir||file.a.b '"'filedes.a.b'"'
  171.                     say indir||file.a.b filedes.a.b
  172.  
  173.                     if openmode='w' then do
  174.                         CALL WRITELN('msgadd'," WFREQIT "sv" by Sean Mollitt & Robert Williamson © 1993")
  175.                         CALL WRITELN('msgadd'," ------------------------------------------------------------")
  176.                     end
  177.                     CALL WRITELN('msgadd',"")
  178.                     CALL WRITELN('msgadd'," File name  : "||file.a.b||"  ("||filek.a.b||")     Freq'ed from: "||filea.a.b)
  179.                     CALL WRITELN('msgadd'," Description: "||filedes.a.b)
  180.                     CALL CLOSE('msgadd')
  181.  
  182.                     smsg='LOG:RFSacct/'translate(name.a,"_"," ")'.m'
  183.                     if exists(smsg) then call open('um',smsg,'A')
  184.                         else  call open('um',smsg,'W')
  185.                     call writeln('um',' WFREQIT file reception report')
  186.                     CALL WRITELN('um'," File name  : "||file.a.b||"  ("||filek.a.b||")     Freq'ed from: "||filea.a.b)
  187.                     CALL WRITELN('um'," Description: "||filedes.a.b)
  188.                     call close('um')
  189.  
  190.                     logentry.c = LEFT(infile.x,20)||"  "||LEFT(name.a,20)||"  "||DATE('E')||"  "||filea.a.b||"  "fileto.a.b
  191.                     filestat.a.b = DATE('E')
  192.                 END
  193.             END 
  194.         END
  195.     END
  196.  
  197.     if c=0 then DO
  198.         call putlog("No incoming files match any waiting user files")
  199.         signal shutdown
  200.     END
  201.  
  202. logit:
  203.     IF ~OPEN('log',logfile,'A') then do
  204.         IF ~OPEN('log',logfile,'W') then do
  205.             SAY "Error! Cannot find log file (freqit.log) "   
  206.             signal shutdown
  207.         END
  208.         CALL WRITELN('log','FREQIT 'sv' LOG FILE')
  209.         CALL WRITELN('log','File requested        User                  Date in    From Node     Destin. ')
  210.         CALL WRITELN('log','-------------------------------------------------------------------------------')
  211.     END
  212.     i=0
  213.     DO i = 1 to c
  214.         CALL WRITELN('log',logentry.i)
  215.     END
  216.     CALL CLOSE('log')
  217.  
  218. openuserfilewrite:
  219.  
  220.     IF ~OPEN('user',usrfile,'W') then do
  221.         SAY "Error! Cannot find the userfile" 
  222.         signal shutdown
  223.     END
  224.  
  225. writeuserfile:
  226.     i=0
  227.     DO o = 1 to totusers
  228.         DO q = 1 to files.o
  229.             i=i+1
  230.             IF file.o.q = "IN" then i=i-1 
  231.         END
  232.         IF i ~= 0 THEN DO
  233.             CALL WRITELN('user',name.o)
  234.             do p = 1 to files.o
  235.                 filedat= LEFT(file.o.p,20)||"  "||RIGHT(filek.o.p,7)||"  "||filed.o.p||"  "||filea.o.p||"  "||LEFT(filestat.o.p,8)||" "||fileto.o.p||" "||filedes.o.p
  236.                 CALL WRITELN('user',filedat)
  237.             END
  238.             CALL WRITELN('user','#')
  239.         END
  240.     END
  241.  
  242.     CALL CLOSE('user')
  243.  
  244.     SAY "User file updated and saved" 
  245.  
  246. shutdown:
  247. EXIT
  248.  
  249.  
  250. /* get filename */
  251. get_fn:
  252.     if LastPos('/', arg(1)) ~= 0 then return SubStr(arg(1), LastPos('/', arg(1)) + 1)
  253.         else if LastPos(':', arg(1)) ~= 0 then return SubStr(arg(1), LastPos(':', arg(1)) + 1)
  254.             else return arg(1)
  255.  
  256. addslash:
  257.     curr = arg(1)
  258.     select
  259.         when right(curr, 1) = ":" then nop
  260.         when right(curr, 1) = "/" then nop
  261.             otherwise curr = curr"/"
  262.     end
  263. return(curr)
  264.  
  265.  putlog:
  266.     say arg(1)
  267.     Address "LOGPROC" "Putlog "loggroup time() arg(1)
  268.  return
  269.